package com.service.impl;


import com.entity.OrderStatus;
import com.entity.Orders;
import com.service.OrderService;

import java.util.List;

import static com.util.Vessel.*;

public class OrderSerImpl implements OrderService {
    //出版订单操作（已弃用）
    @Override
    public void orderOperate(int cId,int tId){
        boolean isFlag = true;
        do {
            System.out.println("请选择你的操作：");
            System.out.println("1:查看菜单 ");
            System.out.println("2:点菜");
            System.out.println("3:查看餐袋");
            System.out.println("4.管理菜品数量");
            System.out.println("5:下单");
            System.out.println("6:查看未支付订单");
            System.out.println("7:付款");
            System.out.println("8:开通VIP(vip享9折)");
            System.out.println("9:查看已支付订单");
            System.out.println("10:vip钱包余额");
            System.out.println("11:退出");
            int choice = scanner.nextInt();
            switch(choice){
                //查看菜单
                case 1:
                    opMenuSer.vsMenusService();
                    break;
                case 2:
                    opMenuSer.orderMeService(cId,tId);
                    break;
                case 3:
                    opMenuSer.vsMealBag(cId,tId);
                    break;
                case 4:
                    opMenuSer.magMealBag(cId,tId);
                    break;
                case 5:
                    placeOrder(cId,tId);
                    break;
                case 6:
                    unPay(cId,tId);
                    break;
                case 7:
                    paySer.PayWay(cId);
                    break;
                case 8:
                    boolean vip = vipImpl.vipJudge(cId);
                    if (!vip){
                        vipSer.joinVip(cId);
                    }else{
                        System.out.println("您已是vip");
                        orderOperate(cId,tId);
                    }
                    break;
                case 9:
                    paid(cId);
                    break;
                case 10:
                    boolean vip1 = vipImpl.vipJudge(cId);
                    if (vip1){
                        double balance = vipImpl.Balance(cId);
                        System.out.println("余额:" + balance);
                    }else{
                        System.out.println("这是vip专属");
                        orderOperate(cId,tId);
                    }
                    break;
            }
        }while(isFlag);
    }

    //初版下单
    @Override
    public void placeOrder(int cId,int tId) {
        System.out.println("餐袋菜品如下:");
        opMenuSer.vsMealBag(cId,tId);
        System.out.println("请输入您的选择:1.确认下单   2.选择下单      3.管理菜品数量     3.加菜    4.退出");
        int choice = scanner.nextInt();
        switch(choice){
            case 1:
                OrderMenu(cId,tId);
                break;
            case 2:
                choiceService(cId,tId);
                break;
            case 3:
                opMenuSer.magMealBag(cId,tId);
                break;
            case 4:
                opMenuSer.orderMeService(cId,tId);
                break;
            case 5:
                orderOperate(cId,tId);
                break;
        }
    }

    //未支付订单
    @Override
    public void unPay(int cId,int tId) {
        List<OrderStatus> orderStatusList = order.unPay(cId);
        int id = 0;
        for(OrderStatus orderStatus : orderStatusList){
            id = orderStatus.getoId();
        }
        if (id != 0){
            System.out.println("订单号\t\t\t" + "菜品编号\t\t\t" + "菜品名称\t\t\t" + "菜品数量\t\t\t\t" +
                    "菜品单价\t\t"  + "菜品状态\t\t\t" + "单个菜品总价\t\t\t");
            for(OrderStatus orderStatus : orderStatusList){
                System.out.println(orderStatus.getoId() + "\t\t\t\t" + orderStatus.getmId() + "\t\t\t\t"+ orderStatus.getmName()
                        + "\t\t\t\t" + orderStatus.getmNumber() + "\t\t\t\t" +orderStatus.getmPrice() + "\t\t\t" +
                        orderStatus.getoStatus() + "\t\t\t" + orderStatus.getPrice());
            }
            System.out.println("现在是否付款:1.是    2.暂时退出");
            int pay = scanner.nextInt();
            if (pay == 1){
                paySer.PayWay(cId);
            }
        }else {
            System.out.println("无未支付订单!");
        }
    }

    //确认下单
    @Override
    public void OrderMenu(int cId,int tId) {
        int num = order.orderMenus(cId);
        if (num > 0){
            System.out.println("下单成功");
        }
    }

    //选择下单
    @Override
    public void choiceService(int cId, int tId) {
        boolean isNext = false;
        int choice = 0;
        do {
            System.out.println("餐袋菜品如下:");
            opMenuSer.vsMealBag(cId,tId);
            System.out.println("请输入需要下单的菜品编号:");
            int mId = scanner.nextInt();
            int num = order.choiceOrder(cId,tId,mId);
            order.orderChoice(cId,tId,mId);
            if (num > 0 ){
                System.out.println("点选成功是否继续？1:继续   2:取消");
                choice = scanner.nextInt();
                System.out.println("购物车菜品如下:");

            }
            isNext = (choice == 1);
        }while (isNext);
    }

    //已支付订单查看
    @Override
    public void paid(int cId) {
        List<OrderStatus> orderStatusList = order.paid(cId);
        System.out.println("订单号\t\t\t" + "菜品编号\t\t\t" + "菜品名称\t\t\t" + "菜品数量\t\t\t\t" +
                "菜品单价\t\t"  + "顾客账号\t\t\t" + "菜品状态\t\t\t" + "单个菜品总价\t\t\t");
        for(OrderStatus orderStatus : orderStatusList){
            System.out.println(orderStatus.getoId() + "\t\t\t\t" + orderStatus.getmId() + "\t\t\t\t"+ orderStatus.getmName()
                    + "\t\t\t\t" + orderStatus.getmNumber() + "\t\t\t\t" +orderStatus.getmPrice() + "\t\t\t" +
                    orderStatus.getcId() + "\t\t\t" +
                    orderStatus.getoStatus() + "\t\t\t" + orderStatus.getPrice());
        }
    }


    //勾选菜品
    @Override
    public int select(int cId,int tId) {
        boolean isFlag = false;
        do {
            System.out.println("购物车信息如下:");
            opMenuSer.vsMealBag(cId,tId);
            System.out.println("请输出入需要勾选的菜品编号");
            int inputId = scanner.nextInt();
            int num = order.select(cId,inputId,tId);
            if (num > 0){
                System.out.println("勾选成功!");
                System.out.println("是否继续勾选:1.继续    2.退出");
            }
            int choice = scanner.nextInt();
            isFlag = (choice ==1 );
        }while(isFlag);
        return 0;
    }

    //全勾选
    @Override
    public int selectAll(int cId, int tId) {
        int num = order.selectAll(cId,tId);
        if (num > 0){
            System.out.println("勾选成功!");
        }
        return 0;
    }

    //全取消勾选
    @Override
    public int cancelAll(int cId, int tId) {
        int num = order.cancelAll(cId,tId);
        if (num > 0){
            System.out.println("全部取消勾选成功!");
        }
        return 0;
    }

    //选择取消勾选
    @Override
    public int cancel(int cId, int tId) {
        boolean isFlag = false;
        do {
            System.out.println("购物车信息如下:");
            opMenuSer.vsMealBag(cId,tId);
            System.out.println("请输出入需要取消勾选的菜品编号");
            int inputId = scanner.nextInt();
            int num = order.cancel(cId,inputId,tId);
            if (num > 0){
                System.out.println("取消勾选成功!");
                System.out.println("是否继续取消勾选:1.继续    2.退出");
            }
            int choice = scanner.nextInt();
            isFlag = (choice ==1 );
        }while(isFlag);
        return 0;
    }

    //改变菜品勾选状态
    @Override
    public void alter(int cId, int mId, int tId) {
        int num = order.alter(cId,mId,tId);
        if (num > 0){
            System.out.println("更改成功!");
        }
    }

    //评论与评论判断
    @Override
    public void comment(int cId) {
        int num = 0;
        System.out.println("如下是已支付订单:");
        orderPaid(cId);
        System.out.println("请输入您要评价的订单号:");
        int inputoId = scanner.nextInt();
        System.out.println("请输入评价:");
        String inputComment = scanner.next();
        num = order.comment(cId,inputoId,inputComment);
        if (num > 0){
            System.out.println("评价成功!");
        }else {
            System.out.println("单个订单仅限评论一次,或您还未结账!");
        }
    }

    //已支付订单
    @Override
    public void orderPaid(int cId) {
        List<Orders> ordersList = order.orderPaid(cId);
        System.out.println("订单号\t\t\t" + "餐桌号\t\t\t"+ "用户ID\t\t\t"+ "下单时间\t\t\t"+ "支付状态\t\t\t"+ "评论\t\t\t");
        for (Orders order : ordersList){
            System.out.println(order.getoId() + "\t\t\t" +order.gettId() + "\t\t\t" +
                    order.getcId() + "\t\t\t" +order.getoTime() + "\t\t\t" +order.getoStatus() +
                    "\t\t\t" + order.getComment());
        }
    }

    //订单评论
    @Override
    public void orderComment() {
        List<Orders> ordersList = order.orderComments();
        int i =1;
        for (Orders order : ordersList){
            System.out.println("评论" + i + ":");
            System.out.println(order.getComment());
            i++;
        }
    }

}
